-- pumpkin_explode
-- create by zhuangsl
-- 玩家死亡自爆
-- 配置：attrib_damage(slime_skill_id, attrib, force)

return {
    apply = function(source, target, skillId, round, para, extra)
        -- 斯巴达专属加成
        local prop = PropM.combine(source, "pumpkin_explode", 1);
        if prop[3] > 0 then
            -- 触发特技发动事件
            EventMgr.fire(event.SPECIAL_SKILL_TRIGGER, { propId = prop[1] });
        end

        -- 计算伤害
        local dungeonId = DungeonM.getDungeonId();
        if dungeonId == nil then
            dungeonId = ME.user.dbase:query("currentDungeon");
        end
        local layerFix = DungeonAreaM.query(dungeonId,"layer_fix");
        local floor = DungeonM.currentLayer();
        local force = floor + 4 * prop[3] + 16;
        local damage = FormulaM.invoke("CALC_BIG_DIVISION", math.pow(force, 3), layerFix + 60, 20000);

        -- 爆炸伤害加成
        prop = PropM.combine(source, "attrib", "explode");
        damage = PropM.apply(prop, damage);

        -- 对在场的怪物造成伤害
        local grid, monster;
        for pos = 1, GRID_SIZE do
            grid = DungeonM.getGridByPos(pos);
            monster = grid.monster;

            if grid:isOpened() and monster and not monster:isDead() then
                -- 增加命中动作
                if SkillM.getSequence(monster) == nil then
                    SkillM.getSequenceList()[monster] = CastSequence.create(source, monster, skillId);
                end
                SkillM.getSequence(monster):hit(source, monster, skillId);
                CombatM.doDamage(source, monster, damage, 0);
            end
        end

        return target;
    end,

    parse = function(desc)
        local arr = string.explode(desc, ",");
        return { arr[1], };
    end,

    -- 解析技能描述
    parseDesc = function(source, skillId, desc, para)
        return desc;
    end,
};
